﻿<script>
  $(document).ready(function(){
      // 获取物品id
      var goods_id = getQueryString('goods_id');
      // 获取单个物品数据
      sdmg("{\"token\":\""+token+"\", \"view_goods\":{\"goods_id\":"+goods_id+"}}");
  })

// 笨方法获取参数
function getQueryString(name) {
  // 解码
    url = decodeURI(url);
    // console.log(url);
    // 正则表达式
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var i = url.indexOf("?");
    if(i==-1){return;}  
    // console.log("i = " + i);
    // console.log("url.substr(i) = " + url.substr(i));
    // console.log("url.substr(i + 1) = " + url.substr(i + 1));
    var r = url.substr(i+1).match(reg);  
    if (r != null) return unescape(r[2]);  
    return null;  
}

// 点击 使用按钮 返回函数
function use(goods_info, quantity) {
  // 解码json
  var goods = JSON.parse(unescape(goods_info));
  sdmg("{\"token\":\""+token+"\", \"use_goods\":{\"goods_id\":"+goods.id+",\"quantity\":"+quantity+"}}");
  
  // 重新加载背包物品数量
  // 物品数量不为0
  if(goods.quantity - quantity > 0){
      $(".goods_"+goods.id +" span").html(goods.quantity - quantity);
  }
  // 重新加载当前类别
  else {
     // 重新加载背包
      $.get(host + "/backpack", {action:"getBackPack", category:0}, function(ret){
         console.log(JSON.stringify(ret));
         var backpack = ret.backpack;
         // 类别
         var category = ret.category;
         // 物品
         var goods = ret.goods;
         // 类别为全部
         var desc = $(".goods_category").html();
         console.log($(".goods_category").html());

         if(desc == "分类筛选"){
           goods_category(-1, "分类筛选");
         }
         // 类别为其他的
         else{
           goods_category(goods_category, desc);
         }
     }, "json");
  }
}

// 重新加载背包物品
function renew_backpack_goods(quantity){

}

</script>

<!-- 物品弹窗 -->
<div class="tkbox1_con1" id="zb">
    <div class="zb"><div class="zb_img"><img src="" alt=""></div><span class="zb_mc"></span></div>
    <div class="star_box"><span class="star"></span></div>
    <div class="zb_txt1">
      <span class="zbtxt1_r">剑·150级</span>
    </div>

    <!-- 附加属性 -->
    <div class="zb_txt2" style="display: none;">
      <div class="zb_tit01"><span class="zbtit01_txt">附加属性</span><span class="zbtit01_line"></span></div>
      <p class="goods_attr"></p>
    </div>

    <div class="zb_txt3">
     <p>长剑当向秋水诉，颇觉斗量无痕风。</p>
      <p>秋水无痕剑剑身为血色暗红，呈现出奇异的彩色光泽。相传为剑中之祖昆吾剑的剑柄所炼。</p>
    </div>

    <!-- 事件按钮 -->
    <div class="zb_cz goods_but"></div>
 </div>
 <!-- 关闭按钮 -->
<div class='tk_button'><a class='but03' name='gb'>关闭</a></div>